package cn.tutu.blockchain.wallet.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.tutu.blockchain.exception.BusinessException;
import cn.tutu.blockchain.sysuser.dao.SysUserDao;
import cn.tutu.blockchain.sysuser.entity.SysUser;
import cn.tutu.blockchain.wallet.dao.WalletDao;
import cn.tutu.blockchain.wallet.entity.Wallet;
import cn.tutu.blockchain.wallet.service.WalletService;

@Service
public class WalletServiceImpl implements WalletService {

	@Autowired
	private WalletDao walletDao;

	@Autowired
	private SysUserDao sysUserDao;

	@Override
	public void create(Wallet wallet) {
		// TODO Auto-generated method stub
		SysUser user = sysUserDao.findByPhone(wallet.getPhone());
		if (null == user) {
			throw new BusinessException("该手机用户尚未注册!");
		}
		walletDao.insert(wallet);
	}

	@Override
	public Wallet getByPhone(String phone) {
		// TODO Auto-generated method stub
		return walletDao.findByPhone(phone);
	}

}
